﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class FlagCollisionScript : MonoBehaviour
{
	public GameObject congPanel;
	public GameObject ball;
	public AudioSource congo1;
	public AudioSource congo2;
	public AudioSource baground;

    public Text scoreText;
    int score;

    void Start()
	{
		Time.timeScale = 1f;
    }

	void OnCollisionEnter2D (Collision2D other)
	{

		if (other.gameObject.CompareTag ("Ball")) 
		{
			ball.SetActive (false);
            StartCoroutine(InstantiateAfterDelay(1.2f));
        }
    }

    IEnumerator InstantiateAfterDelay(float delay)
    {
        yield return new WaitForSeconds(delay);

        score = int.Parse(scoreText.text);
        ScoringSystem.theScore = score;
        congPanel.SetActive(true);
        Time.timeScale = 0f;
        congo1.Play();
        congo2.Play();
        baground.Stop();
        int levelReached = PlayerPrefs.GetInt("levelReached", 1);
        levelReached = levelReached + 1;
        PlayerPrefs.SetInt("levelReached", levelReached);

    }
}
